翻訳と辞書 |
nested function : ウィキペディア英語版 | nested function In computer programming, a nested function (or nested procedure or subroutine) is a function which is defined within another function, the ''enclosing function''. Due to simple recursive scope rules, a nested function is itself invisible outside of its immediately enclosing function, but can see (access) all local objects (data, functions, types, etc.) of its immediately enclosing function as well as of any function(s) which, in turn, encloses that function. The nesting is theoretically possible to any ideas of depth, although only a few levels are normally used in practical programs. Nested functions are used in many approaches to structured programming, including early ones, such as ALGOL, Simula 67 and Pascal, and also in many modern dynamic languages and functional languages. However, they are traditionally not supported in the (originally simple) C-family of languages. ==Effects== Nested functions assumes function scope or block scope and have a number of scope related effects. The scope of the nested function is inside the enclosing function, which means that it is invisible outside of it. The nested function is in the scope of local variables of the enclosing function (if they have function scope), or of local variables in the top block of the function (if they have block scope), and likewise other local functions, constants, types, classes, etc. This means it can access these entities, both for reading and writing, without explicit passing: it can access the enclosing environment, which greatly simplifies passing data into and out of the nested function. Further, nested functions may allow closures to be created. If it is possible for the nested function (or a reference to it) to escape the enclosing function – for example if functions are first class objects and a nested function is passed (downwards) to another function or returned (upwards) from the enclosing function – then a closure is created and calls to this function can access the environment of the original function. Notably, the frame of the immediately enclosing function must continue to be alive until the last referencing closure dies. This significantly complicates implementation and code analysis, since non-local automatic variables referenced in closures cannot be stack allocated, and is a key reason nested functions are not implemented in some languages; this is known as the funarg problem. This becomes significantly more complicated if functions are nested to various levels, sharing different parts of their environment.
抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「nested function」の詳細全文を読む
スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース |
Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.
|
|